package com.yss.sofa.report.engine.cell.visible;

import org.apache.commons.lang3.StringUtils;

import com.yss.sofa.report.engine.Const;
import com.yss.sofa.report.engine.cell.ReportCell;

public class SimpleCell extends VisibleCell {
	private static final long serialVersionUID = 4326051290607954723L;
	private String value;
	private SimpleCell(){
		super();
	}
	public SimpleCell(String value){
		this();
		this.setValue(value);
	}
	public String getValue() {
		return value;
	}
	private void setValue(String value) {
		this.dataType=Const.CELL_DATA_TYPE_STRING;
		String _=value;
		if(StringUtils.isNotEmpty(value)){
			char first=value.charAt(0);
			switch (first) {
			case '*':
			case '+':
			case '?':
				_ = value.substring(1);
				this.move=Const.CELL_MOVE_ABS;
				break;
			case '-':
				_ = value.substring(1);
				this.move=Const.CELL_MOVE_RIGHT;
				break;
			case '|':
				_ = value.substring(1);
				this.move=Const.CELL_MOVE_BOTTOM;
				break;
			default:
				this.move=Const.CELL_MOVE_ABS;
				break;
			}
			String tmp=_;
			if(tmp.startsWith("=")){
				_ = tmp.substring(1);
				this.dataType=Const.CELL_DATA_TYPE_EXP;
			} else if(tmp.startsWith("~")){
				_ = tmp.substring(1);
				this.dataType=Const.CELL_DATA_TYPE_DYNAMIC_STRING;
			}
		} else {
			this.move=Const.CELL_MOVE_ABS;
		}
		this.value=_;
	}

	protected void init() {
		super.init();
		this.type=Const.REPORT_CELL_TYPE_SIMPLE;		
	}
	public void assignTo(ReportCell cell){
		SimpleCell _=(SimpleCell)cell;
		super.assignTo(_);
		_.value=this.value;
		_.dataType=this.dataType;
		_.move=this.move;
	}
	public SimpleCell create(){
		SimpleCell _=new SimpleCell();
		this.assignTo(_);
		return _;
	}
}
